package com.baizhi.controller;

import com.baizhi.exception.EnumException;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionController {

    @ExceptionHandler(EnumException.class)
    public ResponseEntity<String> handlerException(EnumException e){
        return new ResponseEntity<>(e.getMessage(), HttpStatusCode.valueOf(e.getCode()));
    }
}
